package org.example.service;

import org.example.dao.UserDao;
import org.example.dao.UserDaoImpl;
import org.example.entity.User;
import org.example.factory.UserDaoFactory;

public class UserServiceImpl implements UserService{
    private UserDao user;   //声明接口类型的引用，和具体实现类解耦合
    //UserDao userDao = new UserDaoImpl();
    private UserDao userDao = UserDaoFactory.getInstance();  //通过工厂获取所依赖的UserDao对象

    /**
     * 无参构造方法
     */
    public UserServiceImpl(){

    }
    public UserServiceImpl(UserDao dao){
        this.user=dao;
    }
    /**
     * 保存用户
     * @param user
     */
    @Override
    public void save(User user) {
        userDao.save(user);
    }
    /*
    dao属性的setter访问器，会被Spring调用实现依赖注入
     */
    public void setUserDao(UserDao userDao) {
        this.user = userDao;
    }
}
